import httpsRequest from '@/assets/httpsRequest';

export default {
  namespaced: true,
  state: {
    imagesList: [],
    imagesCategory: [],
  },
  actions: {
    async getImagesList({ commit }, { payload }) {
      const res = await httpsRequest({
        url: `getimages/${payload.categoryId}`,
      });
      const { status, data = {} } = res;
      const { message = [] } = data;
      if (status === 200) {
        commit({
          type: 'setImagesList',
          payload: {
            imagesList: message,
          },
        });
      }
    },
    async getImagesCategory({ commit }) {
      const res = await httpsRequest({
        url: 'getimgcategory',
      });
      const { status, data = {} } = res;
      const { message = [] } = data;
      if (status === 200) {
        message.unshift({
          title: '全部种类',
          id: 0,
        });
        commit({
          type: 'setImagesCategory',
          payload: {
            imagesCategory: message,
          },
        });
      }
    },
  },
  mutations: {
    setImagesList(state, { payload }) {
      Object.assign(state, payload);
    },
    setImagesCategory(state, { payload }) {
      Object.assign(state, payload);
    },
  },
  getters: {
  },
};
